package com.itcast.myrpc.test;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

/**
 * @program: bio_tcp
 * @description: 丢弃已读字节
 * @author: zhanghz001
 * @create: 2021-02-22 11:52
 **/
public class ByteBufTest03 {
    public static void main(String[] args) {
        //构建
        ByteBuf byteBuf = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
        //查看相关信息
        System.out.println("byteBuf容量: " + byteBuf.capacity());
        System.out.println("byteBuf可写容量为: " + byteBuf.writableBytes());
        System.out.println("byteBuf可读容量为: " + byteBuf.readableBytes());
        System.out.println("=================");
        //读取吧
        while (byteBuf.isReadable()) {
            System.out.println((char) byteBuf.readByte());
        }
        System.out.println("byteBuf容量: " + byteBuf.capacity());
        System.out.println("byteBuf可写容量为: " + byteBuf.writableBytes());
        System.out.println("byteBuf可读容量为: " + byteBuf.readableBytes());
        System.out.println("=================");
        
        byteBuf.discardReadBytes();
        System.out.println("byteBuf容量: " + byteBuf.capacity());
        System.out.println("byteBuf可写容量为: " + byteBuf.writableBytes());
        System.out.println("byteBuf可读容量为: " + byteBuf.readableBytes());
        System.out.println("=================");
    }
}
